//
//  QBVCMain.m
//  QiuBai
//
//  Created by yaohongchao on 16/4/17.
//  Copyright © 2016年 yaohongchao. All rights reserved.
//

#import "QBVCMain.h"
#import "QBVCZone.h"
#import "QBVCDiscover.h"
#import "QBVCNotes.h"
#import "QBVCMe.h"
#import "QBVCQiuShi.h"


@interface QBVCMain ()

@end

@implementation QBVCMain

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(CYLTabBarController*)tabBarController{
    NSArray *arrClass = @[[NSClassFromString(@"QBVCQBSpecial") class],
                          [NSClassFromString(@"QBVCVideo") class],
                          [NSClassFromString(@"QBVCWords") class],
                          [NSClassFromString(@"QBVCImage") class],
                          [NSClassFromString(@"QBVCEssence") class],
                          ];
    NSArray *titiles = @[@"专享",@"视频",@"纯文",@"纯图",@"精华"];
    QBVCQiuShi *vcQiushi = [[QBVCQiuShi alloc]initWithViewControllerClasses:arrClass andTheirTitles:titiles];
    vcQiushi.menuViewStyle = WMMenuViewStyleDefault;
    vcQiushi.bounces = YES;
    vcQiushi.showOnNavigationBar = YES;
    vcQiushi.menuItemWidth = 55.0f;
    vcQiushi.progressHeight = 3.5;
    vcQiushi.titleSizeNormal = 16;
    vcQiushi.titleSizeSelected = 16;
    vcQiushi.menuBGColor = [UIColor clearColor];
    vcQiushi.menuViewContentMargin = 50;
    vcQiushi.titleColorNormal = [UIColor colorWithHexString:@"#9c9ca1"];
    vcQiushi.titleColorSelected = [UIColor colorWithHexString:@"#ffa100"];

    
    UIViewController *navQiushi = [[UINavigationController alloc]
                                   initWithRootViewController:vcQiushi];
    
    QBVCZone *vcZone = [[QBVCZone alloc] init];
    UIViewController *navZone = [[UINavigationController alloc]
                                 initWithRootViewController:vcZone];
    
    QBVCDiscover *vcDiscover = [[QBVCDiscover alloc] init];
    UIViewController *navDiscover = [[UINavigationController alloc]
                                     initWithRootViewController:vcDiscover];
    
    QBVCNotes *vcNotes = [[QBVCNotes alloc] init];
    UIViewController *navNotes = [[UINavigationController alloc]
                                  initWithRootViewController:vcNotes];
    
    QBVCMe *vcMe = [[QBVCMe alloc] init];
    UIViewController *navMe = [[UINavigationController alloc]
                               initWithRootViewController:vcMe];
    
    CYLTabBarController *tabBarController = [[CYLTabBarController alloc] init];
    tabBarController.tabBar.dk_barTintColorPicker = DKColorPickerWithKey(CellSelectedBg);
    
    [self customizeTabBarForController:tabBarController];
    [tabBarController setViewControllers:@[navQiushi,navZone,navDiscover,navNotes,navMe]];
    self.tabBarController = tabBarController;
    [self customizeTabBarAppearance:tabBarController];
    return tabBarController;
}

- (void)customizeTabBarAppearance:(CYLTabBarController *)tabBarController {
    // set the text color for unselected state
    // 普通状态下的文字属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    // set the text color for selected state
    // 选中状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#ffa100"];
    
    // set the text Attributes
    // 设置文字属性
    UITabBarItem *tabBar = [UITabBarItem appearance];
    [tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
  
    [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tapbar_top_line"]];
}


- (void)customizeTabBarForController:(CYLTabBarController *)tabBarController {
    
    NSDictionary *dict1 = @{
                            CYLTabBarItemTitle : @"糗事",
                            CYLTabBarItemImage : @"qb_tab_main_nor",
                            CYLTabBarItemSelectedImage : @"qb_tab_main_sel"
                            };
    NSDictionary *dict2 = @{
                            CYLTabBarItemTitle : @"糗友圈",
                            CYLTabBarItemImage : @"qb_tab_friends_nor",
                            CYLTabBarItemSelectedImage : @"qb_tab_friends_sel"
                            };
    NSDictionary *dict3 = @{
                            CYLTabBarItemTitle : @"发现",
                            CYLTabBarItemImage : @"qb_tab_discovery_nor",
                            CYLTabBarItemSelectedImage : @"qb_tab_discovery_sel"
                            };
    NSDictionary *dict4 = @{
                            CYLTabBarItemTitle : @"小纸条",
                            CYLTabBarItemImage : @"qb_tab_messege_nor",
                            CYLTabBarItemSelectedImage : @"qb_tab_messege_sel"
                            };
    NSDictionary *dict5 = @{
                            CYLTabBarItemTitle : @"我",
                            CYLTabBarItemImage : @"qb_tab_me_nor",
                            CYLTabBarItemSelectedImage : @"qb_tab_me_sel"
                            };
    
    NSArray *tabBarItemsAttributes = @[ dict1, dict2,dict3,dict4,dict5 ];
    tabBarController.tabBarItemsAttributes = tabBarItemsAttributes;
}

@end
